/*
  Copyright © 2010  Vinícius dos Santos Oliveira

      This file is part of Touché.

      Touché is free software: you can redistribute it and/or modify
      it under the terms of the GNU Lesser General Public License as published
      by the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU Lesser General Public License for more details.

      You should have received a copy of the GNU Lesser General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */

#ifndef TEXTELEMENT_H
#define TEXTELEMENT_H

#include "toucheelement.h"

#ifndef TOUCHE_SHOULD_SKIP_THIS
class TextItem: public QGraphicsTextItem
{
    Q_OBJECT

    QTextDocument *m_document;

protected:
    void keyPressEvent(QKeyEvent *event);
    void focusOutEvent(QFocusEvent *event);

public:
    TextItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

signals:
    void finished();
};

#endif

namespace Touche {

    class TextElement : public Element
    {
        Q_OBJECT

        bool locked;
        QString buffer;
#ifndef TOUCHE_SHOULD_SKIP_THIS
        TextItem *m_item;
#else
        QGraphicsTextItem *m_item;
#endif

    public:
        TextElement();
        const QString &type() const;
        QRectF item(QGraphicsItem *parentItem) const;
        QVector<QString> menuOptions() const;

        QString save() const;
        void load(const QString &xml, const QStringList &listFiles);

    public slots:
        void onMenuActived(const QString &option);
        void onElementLocked(bool locked);

    private slots:
#ifndef TOUCHE_SHOULD_SKIP_THIS
        void onEditionFinished();
#else
        void onEditionFinished();
#endif
    };

} // namespace Touche

#endif // TEXTELEMENT_H
